<template>
  <el-dialog
    title="分配角色"
    width="600px"
    :visible="isShow"
    @close="cancelEvent"
  >
    <el-checkbox-group v-model="value">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">
        {{ item.name }}
      </el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <div style="text-align: center">
        <el-button type="primary" @click="submit">提交</el-button>
        <el-button @click="cancelEvent">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { sysRole } from '@/api/setting'
import { sysUser } from '@/api/user'
import { sysUserAssignRoles } from '@/api/employees'
export default {
  props: {
    isShow: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      list: [],
      value: [],
      id: ''
    }
  },
  created() {
    this.getData()
  },
  methods: {
    cancelEvent() {
      this.$emit('update:isShow', false)
      this.value = []
    },
    async getData() {
      const res = await sysRole({
        page: 1,
        pagesize: 1000
      })
      this.list = res.data.rows
    },
    async getUserInfo(id) {
      this.id = id
      const res = await sysUser(id)
      this.value = res.data.roleIds
    },
    async submit() {
      await sysUserAssignRoles(this.id, this.value)
      this.cancelEvent()
      this.$message.success('修改成功')
    }
  }
}
</script>

<style></style>
